﻿using UnityEngine;
using UnityEngine.UI;


namespace UIElement
{
    public class CommonListItem : MonoBehaviour
    {
        protected OnSelectDelegate OnSelectItem = null;
        protected OnShowDelegate OnShowItem = null;
        private int mValue = -1;
        public Image mBtn = null;
        public int Value
        {
            get
            {
                return mValue;
            }
            set
            {
                mValue = value;
            }
        }
        public void SetItemData(int value)
        {
            gameObject.SetActive(true);
            // 只有不一样的，才会刷新
            Value = value;
            OnShowItem?.Invoke(this);
        }

        public void Init(OnSelectDelegate selctItemFunc, OnShowDelegate showItemFunc)
        {
            OnSelectItem = selctItemFunc;
            OnShowItem = showItemFunc;
            if (mBtn != null)
            {
                ClickEventListener listener = ClickEventListener.Get(mBtn.gameObject);
                listener.SetClickEventHandler(OnClickSelect);
            }
        }

        public void OnClickSelect(GameObject obj)
        {
            OnSelectItem?.Invoke(this);
        }

    }
}